package com.example.jiwhsgs;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class LTactivity extends Activity {
    private int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lt);

        final TextView textView = findViewById(R.id.LTtextView);
        final Button button_add = findViewById(R.id.LTbuttonAdd);
        final Button button_sub = findViewById(R.id.LTbuttonSub);

        button_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (count >= 0) {
                    count++;
                    String str = judgeCount(textView);
                    textView.setText(str);
                }
            }
        });

        button_sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (count > 1) {
                    count--;
                    String str = judgeCount(textView);
                    textView.setText(str);
                }
            }
        });
    }

    public String judgeCount(TextView textView) {
        String str = "";
        str += String.valueOf(count);
        str += '\n';
        if (count % 3 == 0) //被3整除
        {
            //生成0或1的随机数
            Random random = new Random();
            int randomNumber = random.nextInt(2);
            if (randomNumber == 0)
                str += "杀\n";
            else str += "闪\n";
        }
        if (count % 5 == 0) {
            Random random = new Random();
            int randomNumber = random.nextInt(2);
            if (randomNumber == 0)
                str += "酒\n";
            else str += "桃\n";
        }
        if (count % 8 == 0) {
            Random random = new Random();
            int randomNumber = random.nextInt(2);
            if (randomNumber == 0)
                str += "无中生有";
            else str += "决斗";
        }
        return str;
    }
}
